using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Terra.Core.Common.Enums.Logging;

namespace Terra.Data.Entities.Logging;

/// <summary>
/// 异常日志实体
/// </summary>
[Table("ExceptionLogs")]
[Comment("异常日志表")]
[Index(nameof(ExceptionTime))]
[Index(nameof(TraceId))]
[Index(nameof(Severity))]
public class ExceptionLog : LogEntityBase
{
    /// <summary>
    /// 异常类型
    /// </summary>
    [Required]
    [MaxLength(256)]
    [Comment("异常类型")]
    public string ExceptionType { get; set; }

    /// <summary>
    /// 异常消息
    /// </summary>
    [Required]
    [Comment("异常消息")]
    public string ExceptionMessage { get; set; }

    /// <summary>
    /// 异常堆栈
    /// </summary>
    [Comment("异常堆栈信息")]
    public string StackTrace { get; set; }

    /// <summary>
    /// 异常源
    /// </summary>
    [MaxLength(256)]
    [Comment("异常来源")]
    public string Source { get; set; }

    /// <summary>
    /// 异常时间
    /// </summary>
    [Required]
    [Comment("异常发生时间")]
    public DateTime ExceptionTime { get; set; }

    /// <summary>
    /// 请求跟踪ID
    /// </summary>
    [MaxLength(100)]
    [Comment("请求跟踪ID")]
    public string TraceId { get; set; }

    /// <summary>
    /// 请求路径
    /// </summary>
    [MaxLength(256)]
    [Comment("发生异常的请求路径")]
    public string RequestPath { get; set; }

    /// <summary>
    /// 请求方法
    /// </summary>
    [MaxLength(10)]
    [Comment("HTTP请求方法")]
    public string RequestMethod { get; set; }

    /// <summary>
    /// 异常严重程度
    /// </summary>
    [Required]
    [Comment("异常严重程度")]
    public ExceptionSeverity Severity { get; set; }
}

